package base

import (
	"gitee.com/ymofen/gobase"
	"gitee.com/ymofen/golog"
)

type PlgBase struct {
	PlugId     string
	closeFuncs *gobase.SyncFuncList
	Log        golog.Logger
}

func (this *PlgBase) OnCreate() {
	this.closeFuncs = gobase.NewSyncFuncList()
	this.Log = golog.Default()
}

func (this *PlgBase) AddCloseFunc(id string, argsFunc gobase.ArgsFunc, args ...interface{}) {
	this.closeFuncs.AddOrSet(id, argsFunc, args...)
}

func (this *PlgBase) RemoveCloseFunc(id string) {
	this.closeFuncs.Remove(id)
}

func (this *PlgBase) RemoveAndCloseFunc(id string) {
	this.closeFuncs.ExecuteAndRemove(id)
}

func (this *PlgBase) ExecuteAllAndClose() {
	this.closeFuncs.ExecuteAndRemoveAll()
}
